package com.sinothk.fc.bo.demand.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sinothk.fc.bo.demand.entity.BoDemandEntity;
import com.sinothk.fc.bo.demand.entity.BoDemandSearchReq;
import com.sinothk.fc.bo.demand.entity.BoDemandVO;
import com.sinothk.fc.bo.demand.service.IBoDemandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @Description: 商机需求信息
 * @Author: Liangyt
 * @Date: 2022-07-17
 * @Version: V1.0
 */
@Api(tags = "商机需求信息")
@RestController
@RequestMapping("/fc/boDemandCtrl")
@Slf4j
public class BoDemandController extends JeecgController<BoDemandEntity, IBoDemandService> {
    @Autowired
    private IBoDemandService boBiddingService;

    /**
     * 分页列表查询
     *
     * @param boBiddingEntity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "商机需求信息-分页列表查询")
    @ApiOperation(value = "商机需求信息-分页列表查询", notes = "商机需求信息-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(BoDemandEntity boBiddingEntity,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<BoDemandEntity> queryWrapper = QueryGenerator.initQueryWrapper(boBiddingEntity, req.getParameterMap());
        Page<BoDemandEntity> page = new Page<BoDemandEntity>(pageNo, pageSize);
        IPage<BoDemandEntity> pageList = boBiddingService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询-登录人求购
     *
     * @param beanReq
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "分页列表查询-登录人求购")
    @ApiOperation(value = "分页列表查询-登录人求购", notes = "分页列表查询-登录人求购")
    @GetMapping(value = "/listForMinePage")
    public Result<?> listForMinePage(BoDemandEntity beanReq,
                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                     HttpServletRequest req) {
        return Result.OK(boBiddingService.listForMinePage(new Page<>(pageNo, pageSize), beanReq, req));
    }

    /**
     * 分页列表查询-登录人收到的邀请
     *
     * @param searchReq
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "分页列表查询-登录人收到的邀请")
    @ApiOperation(value = "分页列表查询-登录人收到的邀请", notes = "分页列表查询-登录人收到的邀请")
    @GetMapping(value = "/demandSupplyForMePage")
    public Result<IPage<BoDemandVO>> demandSupplyForMePage(BoDemandSearchReq searchReq,
                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {
        return Result.OK(boBiddingService.demandSupplyForMePage(new Page<>(pageNo, pageSize), searchReq));
    }

    /**Su
     * 分页列表查询-新商机
     *
     * @param searchReq
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "分页列表查询-新商机")
    @ApiOperation(value = "分页列表查询-新商机", notes = "分页列表查询-新商机")
    @GetMapping(value = "/listForBo")
    public Result<?> listForBo(BoDemandSearchReq searchReq,
                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return Result.OK(boBiddingService.listForBo(new Page<>(pageNo, pageSize), searchReq));
    }

//    /**
//     * 添加
//     *
//     * @param boBiddingEntity
//     * @return
//     */
//    @AutoLog(value = "商机需求信息-添加")
//    @ApiOperation(value = "商机需求信息-添加", notes = "商机需求信息-添加")
//    @PostMapping(value = "/add")
//    public Result<?> add(@RequestBody BoBiddingEntity boBiddingEntity) {
//        return Result.OK(boBiddingService.add(boBiddingEntity));
//    }

    /**
     * 添加或编辑
     *
     * @param boBiddingEntity
     * @return
     */
    @AutoLog(value = "商机需求信息-添加或编辑")
    @ApiOperation(value = "商机需求信息-添加或编辑", notes = "商机需求信息-添加或编辑")
    @PostMapping(value = "/addOrUpdate")
    public Result<?> addOrUpdate(@RequestBody BoDemandEntity boBiddingEntity) {
        return Result.OK(boBiddingService.addOrUpdate(boBiddingEntity));
    }

//    /**
//     * 编辑
//     *
//     * @param boBiddingEntity
//     * @return
//     */
//    @AutoLog(value = "商机需求信息-编辑")
//    @ApiOperation(value = "商机需求信息-编辑", notes = "商机需求信息-编辑")
//    @PutMapping(value = "/edit")
//    public Result<?> edit(@RequestBody BoBiddingEntity boBiddingEntity) {
//        boBiddingService.updateById(boBiddingEntity);
//        return Result.OK("编辑成功!");
//    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "商机需求信息-通过id删除")
    @ApiOperation(value = "商机需求信息-通过id删除", notes = "商机需求信息-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        boBiddingService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "商机需求信息-批量删除")
    @ApiOperation(value = "商机需求信息-批量删除", notes = "商机需求信息-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.boBiddingService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "商机需求信息-通过id查询")
    @ApiOperation(value = "商机需求信息-通过id查询", notes = "商机需求信息-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        BoDemandEntity boBiddingEntity = boBiddingService.getById(id);
        if (boBiddingEntity == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(boBiddingEntity);
    }

    /**
     * 更新状态
     *
     * @param id
     * @return
     */
    @AutoLog(value = "商机需求信息-通过id查询")
    @ApiOperation(value = "商机需求信息-通过id查询", notes = "商机需求信息-通过id查询")
    @GetMapping(value = "/updateState")
    public Result<?> updateState(@RequestParam(name = "id") String id, @RequestParam(name = "state") int state) {
        BoDemandEntity boBiddingEntity = boBiddingService.getById(id);
        if (boBiddingEntity == null) return Result.error("未找到对应数据");
        boBiddingEntity.setState(state);
        boBiddingService.updateById(boBiddingEntity);
        return Result.OK(boBiddingEntity);
    }

}
